package org.itboys.weixin.service;

import org.itboys.weixin.constant.WeixinConstants;
import org.itboys.weixin.entity.WeixinConfig;
import org.itboys.weixin.tools.WeixinUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微信二维码的创建
 * @author weisky
 *
 * 2016年4月14日
 */
@Service
public class WeixinTwoCodeService {
	
	@Autowired
	private WeixinConfigService weixinConfigService;

	/**
	 * 生成带参数的临时二维码
	 * @param paramId : 二维码携带的参数ID
	 * @param weixinId ： 微信ID
	 * @param paramId ： 携带的参数ID
	 * @return
	 */
	public String createSceneTwoCode(Long weixinId, Long paramId){
		WeixinConfig wc = weixinConfigService.getById(weixinId);
		String appid = wc.getAppId();
		String secret = wc.getAppSecret();
		String access_token = WeixinUtils.getAccessToken(appid, secret);
		String ticket = WeixinUtils.getTicket(access_token, WeixinConstants.TOW_CODE_TYPE.QR_LIMIT_SCENE, paramId);
		return WeixinConstants.URL.GET_TOWCODE_URL + ticket;
	}
	
}
